package com.example.test.suppert;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * 实体基类
 * <p>
 * Created by lsl on 2021/3/3.
 */
@Data
@NoArgsConstructor
@SuperBuilder
@MappedSuperclass
@JsonInclude(JsonInclude.Include.NON_NULL)
public class BaseDo implements Serializable {
    private static final long serialVersionUID = -1733849641032268568L;
    @Id
    @GeneratedValue
    @Column(columnDefinition = "bigint comment '主键Id'")
    @TableId(value = "id", type = IdType.INPUT)
    protected Long id;

    @TableField("create_date")
    @Column(columnDefinition = "timestamp null default null comment '创建数据时间'")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    protected Date createDate;

    @TableField("update_date")
    @Column(columnDefinition = "timestamp null default null comment '更新数据时间'")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    protected Date updateDate;

    @TableField("deleted")
    @Column(columnDefinition = "tinyint default 0 comment '逻辑删除 1删除 0未删除'")
    protected Integer deleted;

    @TableField("version")
    @Column(columnDefinition = "int default 0 comment '乐观锁'")
    @Version
    protected Integer version;

    /**
     * 页码
     */
    @Transient // jpa忽略
    @TableField(exist = false) // mp忽略
    private Integer pageBegin;

    /**
     * 页大小
     */
    @Transient
    @TableField(exist = false)
    private Integer pageSize;
}
